package cn.tedu.springboot01;

import cn.tedu.springboot01.dao.UserDao;
import cn.tedu.springboot01.entity.User;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

/**
 * 不依附于mybatis框架，利用Mockito框架，创建userDao模拟对象
 */
public class JunitTest02 {

    UserDao userDao;
    User user;

    @BeforeEach
    void init(){
        // mock 模拟
        // mockito进行模拟创建对象
        userDao = Mockito.mock(UserDao.class);
        System.out.println(userDao);
        User user = userDao.findUserByName("tom");
        System.out.println("训练前：" + user);
        // 训练
        Mockito.when(userDao.findUserByName("tom"))
                .thenReturn(new User(1, "tom", "123", "ADMIN"));
    }

    @Test
    void test() {
        // 测试训练结果
        user = userDao.findUserByName("tom");
        System.out.println("训练后：" + user);
    }

}